package me.zhengjie.modules.web.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.config.entity.ResponseBaseEntity;
import me.zhengjie.config.enums.AtmrErrorEnum;
import me.zhengjie.config.exception.WeChatException;
import me.zhengjie.modules.web.domain.index.AtmrListResp;
import me.zhengjie.modules.web.domain.index.IndexResp;
import me.zhengjie.modules.web.service.IIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("web/atmr")
@Api(tags = "前端接口-首页")
public class IndexController {

    @Autowired
    private IIndexService courseService;

    @PostMapping("index")
    @ApiOperation("前端接口-首页")
    public ResponseBaseEntity index() {
        ResponseBaseEntity response = new ResponseBaseEntity();
        try {
            IndexResp list = courseService.index();
            response.setBody(list);
        } catch (WeChatException e) {
            response.getHeader().setErrCode("-1");
            response.getHeader().setErrMsg(e.getMsg());
        } catch (Exception e) {
            response.getHeader().setErrCode(AtmrErrorEnum.EC_ALL_99999.getErrorCode());
            response.getHeader().setErrMsg(AtmrErrorEnum.EC_ALL_99999.getErrorMessage());
        }
        return response;
    }

    @PostMapping("list")
    @ApiOperation("前端接口-测评全部列表")
    public ResponseBaseEntity list() {
        ResponseBaseEntity response = new ResponseBaseEntity();
        try {
            List<AtmrListResp> list = courseService.list();
            response.setBody(list);
        } catch (WeChatException e) {
            response.getHeader().setErrCode("-1");
            response.getHeader().setErrMsg(e.getMsg());
        } catch (Exception e) {
            response.getHeader().setErrCode(AtmrErrorEnum.EC_ALL_99999.getErrorCode());
            response.getHeader().setErrMsg(AtmrErrorEnum.EC_ALL_99999.getErrorMessage());
        }
        return response;
    }
}
